//
//  OrderViewController.m
//  FeiMa
//
//  Created by 艾玩科技 on 17/2/28.
//  Copyright © 2017年 随心. All rights reserved.
//

#import "OrderViewController.h"
#import "ArriveViewController.h"

#import "OrderHeadView.h"
#import "OrderFootView.h"

#import "DriverArrivedTimePickerView.h"//司机到达时间

@interface OrderViewController ()<BNNaviUIManagerDelegate,BNNaviRoutePlanDelegate,PhotoOverDelegate,UITableViewDelegate,UITableViewDataSource,UITextViewDelegate>


{
    UITableView *orderTableView;
    OrderHeadView *orderHeadV;
    NSDictionary *detailOrderDic;
    OrderFootView *orderFootV;
    
    NSString *thisTitle;
    NSString *orderStatusStr;//订单状态
    //键盘将要显示时tableView的偏移量
    CGFloat contentoffy;
    
    UITextView *markTextView;//备注
 
    NSString *telNumStrA;

    NSString *telNumStrB;
    
     UIActivityIndicatorView *indicator;//风火轮
}

@property (nonatomic,strong) UIButton *carBtn;
@property (nonatomic,strong) UIButton *deadheadBtn;

//拖车 OR 非拖车
@property(nonatomic,strong) NSString *istrailStr;
@property(nonatomic,strong) DriverArrivedTimePickerView *pickerView;
@property(nonatomic,strong) UIView *footV;
@end

@implementation OrderViewController


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
#pragma mark --  直接接单过来的 -- 
    if ([self.selectTimeStr integerValue] == 1) {
        
        self.pickerView = [[DriverArrivedTimePickerView alloc]init];
        
    
        self.pickerView.TimeDataSource = @[@"40分钟", @"50分钟", @"60分钟", @"70分钟", @"80分钟", @"90分钟"];
        self.pickerView.sureBtn.titleStr = @"确定";
        [self.pickerView.sureBtn addtimeWithTimeIntValue:600];
        
        
        self.pickerView.time_pickerTitle = @"大概多久能到？";
        __weak typeof(self) weakSelf = self;
        self.pickerView.defaultStr = @"40分钟/1";
        self.pickerView.orderTypeStr = self.seveiceTypeStr;
        self.pickerView.orderAdressStr = self.seveiceAdrssStr;
        self.pickerView.valueDidSelected = ^(NSString *value){
            NSArray * stateArr = [value componentsSeparatedByString:@"/"];

            
            
            [weakSelf.pickerView removeSelfFromSupView_time];
            NSString *arrivetimeStr = [stateArr[0] substringToIndex:2];

          //现在到达时间
            [CoreWork DriverBeSureArriveTimeWithorderNo:weakSelf.orderNumberStr arriveTime:arrivetimeStr loginToken:GetUserLoginToken Block:^(id responsObject) {
                
                
#pragma mark -- 服务器报错  --
                if (![responsObject isKindOfClass:[NSDictionary class]]) {
                    
                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                    
                    [alert addAction:sure];
                    [weakSelf presentViewController:alert animated:YES completion:nil];
                    
                    return ;
                    
                    
                }
                
#pragma mark -- 报错 --
                if (([responsObject isKindOfClass:[NSDictionary class]] ) && ([[responsObject objectForKey:@"status"] integerValue ] == 0) ) {
                    
                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@", [responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                    
                    [alert addAction:sure];
                    [weakSelf presentViewController:alert animated:YES completion:nil];
                    
                    return ;
                }
#pragma mark -- 账号在另一个地方登录，被迫退出 --
                else if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == -3))
                {
                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                        
                        //调用退出接口
                        [CoreWork logOutWithloginToken:GetUserLoginToken Block:^(id responsObject) {
//                             [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
                            [weakSelf.navigationController presentViewController:[[LogInViewController alloc] init] animated:YES completion:nil];
                        }];
                        
                    }];
                    
                    [alert addAction:sure];
                    [weakSelf presentViewController:alert animated:YES completion:nil];
                    
                    return ;
                }

                weakSelf.selectTimeStr = @"2";
                [weakSelf.pickerView removeSelfFromSupView_time];
                
            }];
        };
        [self.pickerView showView];
        
        
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"接单";
    
    //监听键盘显示和隐藏
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBordShowNotifitionCenter:) name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBordHidden) name:UIKeyboardWillHideNotification object:nil];
    
    detailOrderDic = [[NSDictionary alloc] init];
    orderTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40 +64, KScreenWidth,KScreenHeight - 64 -40  ) style:UITableViewStylePlain];
    orderTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    orderTableView.backgroundColor = [UIColor whiteColor];
    //ordertableview的头视图
   orderHeadV = [[[NSBundle mainBundle] loadNibNamed:@"OrderHeadView" owner:nil options:nil] lastObject];
    
#pragma mark -- 导航按钮的点击方法 --
    orderHeadV.firstDaohangBtn.userInteractionEnabled = NO;
     orderHeadV.thirdDaohangBtn.userInteractionEnabled = NO;
    //救援目的地的导航按钮的tag
    orderHeadV.secondDaohangBtn.tag = 20170406 + 1;
    //拖车目的地的导航按钮的tag
    orderHeadV.receivedAddressLabel.tag = 20170406 + 2;
    //设置边框颜色和边框宽度
    orderHeadV.receivedAddressLabel.layer.borderColor = [UIColor colorWithRed:0.000 green:0.808 blue:0.682 alpha:1.00].CGColor;
    orderHeadV.secondDaohangBtn.layer.borderColor = [UIColor colorWithRed:0.000 green:0.808 blue:0.682 alpha:1.00].CGColor;
    orderHeadV.secondDaohangBtn.layer.borderWidth = 1;
    orderHeadV.receivedAddressLabel.layer.borderWidth = 1;
    orderHeadV.secondDaohangBtn.layer.cornerRadius = 2;
    orderHeadV.secondDaohangBtn.layer.masksToBounds =YES;
    orderHeadV.receivedAddressLabel.layer.cornerRadius = 2;
    orderHeadV.receivedAddressLabel.layer.masksToBounds =YES;
    //字体颜色
    orderHeadV.receivedAddressLabel.titleLabel.textColor = [UIColor colorWithRed:0.000 green:0.808 blue:0.682 alpha:1.00];
    orderHeadV.secondDaohangBtn.titleLabel.textColor = [UIColor colorWithRed:0.000 green:0.808 blue:0.682 alpha:1.00];
    
    //救援目的地的导航
    [orderHeadV.secondDaohangBtn  addTarget:self action:@selector(realNavi:) forControlEvents:UIControlEventTouchUpInside];
    //拖车目的地的导航
    [orderHeadV.receivedAddressLabel  addTarget:self action:@selector(realNavi:) forControlEvents:UIControlEventTouchUpInside];
    //拨打电话按钮的点击方法
    orderHeadV.telBtnA.tag = 20170426;
#pragma mark -- 拨打电话的按钮暂时屏蔽掉 --
//    [orderHeadV.telBtnA addTarget:self action:@selector(telBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
//     [orderHeadV.telBtnB addTarget:self action:@selector(telBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    orderTableView.tableHeaderView = orderHeadV;
    [self.view addSubview:orderTableView];
   
#pragma mark -- 尾视图 --
    
    
    _footV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 40)];
    
    _deadheadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_deadheadBtn setTitle:@"空驶取消" forState:UIControlStateNormal];
    _deadheadBtn.frame = CGRectMake(0, 0, KScreenWidth/2, 40);
    _deadheadBtn.backgroundColor = KRGBColor(108, 212, 156, 1);
    _deadheadBtn.layer.cornerRadius = 2;
    _deadheadBtn.layer.masksToBounds = YES;
    [_footV addSubview:_deadheadBtn];
    
    _carBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_carBtn setTitle:@"司机已到达现场" forState:UIControlStateNormal];
    _carBtn.frame = CGRectMake(KScreenWidth/2, 0, KScreenWidth/2, 40);
    _carBtn.layer.cornerRadius = 2;
    _carBtn.layer.masksToBounds = YES;
    _carBtn.backgroundColor = [UIColor colorWithRed:0.337 green:0.682 blue:0.961 alpha:1.00];
    [_carBtn addTarget:self action:@selector(photoCellBtnAct:) forControlEvents:UIControlEventTouchUpInside];
    [_footV addSubview:_carBtn];
    
    
    orderFootV = [[[NSBundle mainBundle] loadNibNamed:@"OrderFootView" owner:nil options:nil] lastObject];
    orderFootV.DriverArrivedBtn.backgroundColor = [UIColor colorWithRed:0.337 green:0.682 blue:0.961 alpha:1.00];
    orderFootV.DriverArrivedBtn.layer.cornerRadius = 2;
    orderFootV.DriverArrivedBtn.layer.masksToBounds = YES;
    [orderFootV.DriverArrivedBtn addTarget:self action:@selector(photoCellBtnAct:) forControlEvents:UIControlEventTouchUpInside];
    
    orderTableView.tableFooterView = orderFootV;
    
    [self loadDetailOrderData];
  
}


#pragma mark 键盘收起和展开时视图的frame
- (void)keyBordShowNotifitionCenter:(NSNotification *)notification{

    orderTableView.top = -200;
    
}
- (void)keyBordHidden{
    

    orderTableView.top = self.orderTypeLabel.bottom;
}
#pragma mark --  获取订单详情  --
-(void)loadDetailOrderData
{
    //加载风火轮
    [self loadActivityView];
    //获取订单详情
    [CoreWork getDetailOrderWithorderNo:self.orderNumberStr loginToken:GetUserLoginToken Block:^(id responsObject) {
        
#pragma mark -- 服务器报错  --
        if (![responsObject isKindOfClass:[NSDictionary class]]) {
            
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            //风火轮停止转动
            [indicator stopAnimating];
            return ;
            
        }
#pragma mark -- 账号在另一个地方登录，被迫退出 --
        else if (([responsObject isKindOfClass:[NSDictionary class]]) && ([[responsObject objectForKey:@"status"] integerValue] == -3))
        {
            
            //风火轮停止转动
            [indicator stopAnimating];
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",[responsObject objectForKey:@"message"]] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                //调用退出接口
                [CoreWork logOutWithloginToken:GetUserLoginToken Block:^(id responsObject) {
//                     [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLogin"];
                    [self.navigationController presentViewController:[[LogInViewController alloc] init] animated:YES completion:nil];
                }];
                
            }];
            
            [alert addAction:sure];
            [self presentViewController:alert animated:YES completion:nil];
            
            return ;
        }
        if (![ [responsObject objectForKey:@"data"] isKindOfClass:[NSDictionary class]]) {
            
            //风火轮停止转动
            [indicator stopAnimating];
            return;
        }
        //风火轮停止转动
         [indicator stopAnimating];
        
        detailOrderDic = [responsObject objectForKey:@"data"];
        //订单状态（到达现场 or 拖车上板 or 订单完成）
        orderStatusStr = [NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"status"]];
        //拖车 OR 非拖车
        self.istrailStr = [NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"istrail"]];

        if ([orderStatusStr integerValue] == 2060) {
            //orderTableView.tableFooterView = orderFootV;
//            orderTableView.tableFooterView = _footV;
            thisTitle = @"司机已到达现场";
        }
        else if ([orderStatusStr integerValue] == 2070)
        {
//            orderTableView.tableFooterView = orderFootV;

           
            if ([[detailOrderDic objectForKey:@"istrail"] integerValue] == 0) {
                
                //非拖车
                thisTitle = @"订单已完成";
                orderTableView.delegate = self;
                orderTableView.dataSource =self;
            }
            else if ([[detailOrderDic objectForKey:@"istrail"] integerValue] == 1)
            {
                //拖车
                 thisTitle = @"拖车已上板";
            }
        }
        else if ([orderStatusStr integerValue] == 2080)
        {
            orderTableView.tableFooterView = orderFootV;
            thisTitle = @"订单已完成";
            orderTableView.delegate = self;
            orderTableView.dataSource =self;
        }
        //为最底部按钮设置title
        [orderFootV.DriverArrivedBtn setTitle:thisTitle forState:UIControlStateNormal];
        
        //订单类型：收费 OR 免费
        self.orderTypeLabel.text = [NSString stringWithFormat:@"该订单为：%@",[detailOrderDic objectForKey:@"billingType"]];
        
        //服务类型
        orderHeadV.severceTypeLabel.text = [NSString stringWithFormat:@"服务类型：%@",[detailOrderDic objectForKey:@"helpTypeText"]];
        //订单编号
        orderHeadV.orderNumLabel.text =[NSString stringWithFormat:@"订单编号：%@",[detailOrderDic objectForKey:@"orderNo"]];
        //案件编号
        orderHeadV.anjianbianhaoLabel.text = [NSString stringWithFormat:@"案件编号：%@",[detailOrderDic objectForKey:@"caseCode"]];
        
        //订单来源
        orderHeadV.orderSourceLabel.text = [NSString stringWithFormat:@"订单来源：%@",[detailOrderDic objectForKey:@"dealerProviderName"]];
        //预估价格
        orderHeadV.yuguPriceLabel.text = [NSString stringWithFormat:@"预估价格：%@",[detailOrderDic objectForKey:@"one_price"]];
        //需救援车辆
        orderHeadV.carTypeLabel.text = [NSString stringWithFormat:@"需救援车辆：%@",[detailOrderDic objectForKey:@"custCarDescr"]];
        //车牌号
        orderHeadV.jiuyuanCarNumLabel.text = [NSString stringWithFormat:@"需救援车牌：%@",[detailOrderDic objectForKey:@"custCarPlate"]];
        //备注
        orderHeadV.beizhuLabel .text = [NSString stringWithFormat:@"备注：%@",[detailOrderDic objectForKey:@"orderMark"]];
        
        //救援联系人姓名
        orderHeadV. jylxrNameLabel.text = [NSString stringWithFormat:@"救援联系人姓名：%@",[detailOrderDic objectForKey:@"custName"]];
        //汽车交付人电话
        orderHeadV.carOwerTelNumLabel.text =[NSString stringWithFormat:@"汽车交付人电话：%@",[detailOrderDic objectForKey:@"custPhone"]];
        //联系电话
        telNumStrA =[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"custPhone"]];
        //救援地址
        orderHeadV.firstAdressLabel.text = [NSString stringWithFormat:@"报案地址：%@",[detailOrderDic objectForKey:@"addr"]];
        
        if ([[detailOrderDic objectForKey:@"istrail"] integerValue] == 0)
        {
           

            [orderHeadV.totalView removeFromSuperview];
            
        }
        //汽车签收人
        orderHeadV.carReceiveNameLabel.text = [NSString stringWithFormat:@"汽车签收人姓名：%@",[detailOrderDic objectForKey:@"destUser"]];
        //汽车签收人电话
        orderHeadV.carReceiveTelLabel.text =[NSString stringWithFormat:@"汽车签收人电话：%@",[detailOrderDic objectForKey:@"destPhone"]];
        telNumStrB = [NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"destPhone"]];
        //拖车目的地
        orderHeadV.carArriveLabel.text =[NSString stringWithFormat:@"拖车目的地：%@",[detailOrderDic objectForKey:@"destAddr"]];
        //拖车目的地为空时，导航按钮隐藏
        if ([detailOrderDic objectForKey:@"destAddr"] == nil || [detailOrderDic objectForKey:@"destAddrLat"] == nil || [detailOrderDic objectForKey:@"destAddrLng"] == nil  ) {
            orderHeadV.receivedAddressLabel.hidden = YES;
        }
        
        [orderTableView reloadData];
    }];
}

- (BOOL)checkServicesInited
{
   
    
    if(![BNCoreServices_Instance isServicesInited])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
                                                            message:@"引擎尚未初始化完成，请稍后再试"
                                                           delegate:nil
                                                  cancelButtonTitle:@"我知道了"
                                                  otherButtonTitles:nil];
        [alertView show];
        return NO;
    }
    return YES;
}

//模拟导航
- (void)simulateNavi:(UIButton*)button
{
    if (![self checkServicesInited]) return;
    //救援目的地
    if (button.tag ==20170406 + 1 ) {
        
        [self startNaviWithlat:[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"helpAddrLat"]] lng:[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"helpAddrLng"]]];
    }
    //拖车目的地
    else if (button.tag == 20170406 + 2)
    {
        [self startNaviWithlat:[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"destAddrLat"]]  lng:[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"destAddrLng"]] ];
    }
    
    
}

//真实GPS导航
- (void)realNavi:(UIButton*)button
{
    if (![self checkServicesInited]) return;
    //救援目的地
    if (button.tag ==20170406 + 1 ) {
        
        [self startNaviWithlat:[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"helpAddrLat"]] lng:[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"helpAddrLng"]]];
    }
    //拖车目的地
    else if (button.tag == 20170406 + 2)
    {
        
        [self startNaviWithlat:[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"destAddrLat"]]  lng:[NSString stringWithFormat:@"%@",[detailOrderDic objectForKey:@"destAddrLng"]] ];
    }
}
//开启导航
- (void)startNaviWithlat:(NSString *)lat lng:(NSString *)lng
{
    BOOL useMyLocation = YES;
    NSMutableArray *nodesArray = [[NSMutableArray alloc]initWithCapacity:2];
    //起点 传入的是原始的经纬度坐标，若使用的是百度地图坐标，可以使用BNTools类进行坐标转化
    CLLocation *myLocation = [BNCoreServices_Location getLastLocation];
    BNRoutePlanNode *startNode = [[BNRoutePlanNode alloc] init];
    startNode.pos = [[BNPosition alloc] init];
    if (useMyLocation) {
        startNode.pos.x = myLocation.coordinate.longitude;
        startNode.pos.y = myLocation.coordinate.latitude;
        startNode.pos.eType = BNCoordinate_OriginalGPS;
    }
    else {
        startNode.pos.x = 113.948222;
        startNode.pos.y = 22.549555;
        startNode.pos.eType = BNCoordinate_BaiduMapSDK;
    }
    [nodesArray addObject:startNode];
    

    
    //终点
    BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];
    endNode.pos = [[BNPosition alloc] init];
    

    endNode.pos.x = [lng doubleValue];
    endNode.pos.y = [lat doubleValue];
    
    endNode.pos.eType = BNCoordinate_BaiduMapSDK;
    [nodesArray addObject:endNode];
    
    //关闭openURL,不想跳转百度地图可以设为YES
    [BNCoreServices_RoutePlan setDisableOpenUrl:YES];
    [BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:nil];
}

#pragma mark - BNNaviRoutePlanDelegate
//算路成功回调
-(void)routePlanDidFinished:(NSDictionary *)userInfo
{
 
    
    //路径规划成功，开始导航
    [BNCoreServices_UI showPage:BNaviUI_NormalNavi delegate:self extParams:nil];
    
    //导航中改变终点方法示例
    /*dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
     BNRoutePlanNode *endNode = [[BNRoutePlanNode alloc] init];
     endNode.pos = [[BNPosition alloc] init];
     endNode.pos.x = 114.189863;
     endNode.pos.y = 22.546236;
     endNode.pos.eType = BNCoordinate_BaiduMapSDK;
     [[BNaviModel getInstance] resetNaviEndPoint:endNode];
     });*/
}

//算路失败回调
- (void)routePlanDidFailedWithError:(NSError *)error andUserInfo:(NSDictionary*)userInfo
{
    
    switch ([error code]%10000)
    {
        case BNAVI_ROUTEPLAN_ERROR_LOCATIONFAILED:
            [self loadAlertVCWithTitle:@"暂时无法获取您的位置,请稍后重试"];
            break;
        case BNAVI_ROUTEPLAN_ERROR_ROUTEPLANFAILED:
            
             [self loadAlertVCWithTitle:@"无法发起导航,请稍后重试"];
            break;
        case BNAVI_ROUTEPLAN_ERROR_LOCATIONSERVICECLOSED:
         
            [self loadAlertVCWithTitle:@"定位服务未开启,请到系统设置中打开定位服务"];
            break;
        case BNAVI_ROUTEPLAN_ERROR_NODESTOONEAR:
           
            [self loadAlertVCWithTitle:@"起终点距离起终点太近"];
            break;
        default:
            
            [self loadAlertVCWithTitle:@"算路失败,请稍后重试"];
            break;
    }
    
  
    
    
}
-(void)loadAlertVCWithTitle:(NSString *)title
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    
    [alert addAction:sure];
    [self presentViewController:alert animated:YES completion:nil];
    return;

}
//算路取消回调
-(void)routePlanDidUserCanceled:(NSDictionary*)userInfo {
    
}


#pragma mark - 安静退出导航

- (void)exitNaviUI
{
    [BNCoreServices_UI exitPage:EN_BNavi_ExitTopVC animated:YES extraInfo:nil];
}

#pragma mark - BNNaviUIManagerDelegate

//退出导航页面回调
- (void)onExitPage:(BNaviUIType)pageType  extraInfo:(NSDictionary*)extraInfo
{
    if (pageType == BNaviUI_NormalNavi)
    {
    }
    else if (pageType == BNaviUI_Declaration)
    {
    }
}
#pragma mark - 到达现场 or 拖车上板  or 订单完成 按钮的点击方法 -
-(void)photoCellBtnAct:(UIButton *)sender
{
  
   
    if ([thisTitle isEqualToString:@"订单已完成"]) {
        
        if ([markTextView.text isEqual: @"备注"]){}else
        {
            //司机完成订单时添加备注
            [CoreWork addBeizhuWithorderNo:self.orderNumberStr orderMark:markTextView.text loginToken:GetUserLoginToken Block:^(id responsObject) {
                
#pragma mark -- 服务器报错  --
                if (![responsObject isKindOfClass:[NSDictionary class]]) {
                    
                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"服务器开小差了，请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
                    
                    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
                    
                    [alert addAction:sure];
                    [self presentViewController:alert animated:YES completion:nil];
                    
                    return ;
                    
                }
#pragma mark -- 备注提交成功，跳转至上传图片界面
                if (([responsObject isKindOfClass:[NSDictionary class]] )&&([[responsObject objectForKey:@"status"] integerValue ]== 1)) {
                    
                    ArriveViewController* arriveVC = [[ArriveViewController alloc] init];
                    arriveVC.photo_orderNumberStr = self.orderNumberStr;
                    arriveVC.photoDelegateA = self;
                    arriveVC.isFitstStr =thisTitle;
                    [self.navigationController pushViewController:arriveVC animated:YES];
                    return;
                }
                
            }];
        }
        
    }
    /////_____________________________我是华丽的分割线______________________/////

        ArriveViewController* arriveVC = [[ArriveViewController alloc] init];
        arriveVC.photo_orderNumberStr = self.orderNumberStr;
        arriveVC.photoDelegateA = self;
        arriveVC.istrailStrA = self.istrailStr;
        arriveVC.isFitstStr =thisTitle;
        [self.navigationController pushViewController:arriveVC animated:YES];
}

//设置底层按钮的title
-(void)sendtitle:(NSString *)title
{
    thisTitle = title;
    if ([title isEqualToString:@"订单已完成"]) {
        
        
//        [self addMarkTextView];
        orderTableView.delegate =self;
        orderTableView.dataSource = self;
    }
    [orderFootV.DriverArrivedBtn setTitle:title forState:UIControlStateNormal];
  
    
}
//创建cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"orderCLLL"];
    cell.backgroundColor = [UIColor whiteColor];
    markTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 10.f , KScreenWidth, 200)];
    markTextView.text = @"备注";
    markTextView.delegate =self;
    [markTextView textFiledHiddenkeyBord1];
    markTextView.textColor = [UIColor blackColor];
    markTextView.backgroundColor = [UIColor colorWithRed:1.000 green:0.000 blue:0.475 alpha:1.00];
    [cell.contentView addSubview:markTextView];
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 210;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
//textView开始编辑时候的代理方法
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if ([textView.text isEqualToString:@"备注"]) {
        
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
    }
    
}
//textView结束编辑时候的代理方法
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if (textView.text.length < 1)
        
    {
        textView.text = @"备注";
        textView.textColor = [UIColor grayColor];
    }
    
    
}
- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];

}
#pragma mark -- 打电话，联系客户 -- 
-(void)telBtnAction:(UIButton *)sender
{
    if (sender.tag == 20170426) {
       

        
        if ([UIApplication instancesRespondToSelector:@selector(canOpenURL:)]) {
            
            NSString *telephonNumber = [NSString stringWithFormat:@"tel://%@",telNumStrA];
            NSURL *url = [NSURL URLWithString:telephonNumber];
            
            if ([[UIApplication sharedApplication] canOpenURL:url]) {
                
                [[UIApplication sharedApplication] openURL:url];
            }
        }
        
    }
    else
    {
      
        if ([UIApplication instancesRespondToSelector:@selector(canOpenURL:)]) {
            
            NSString *telephonNumber = [NSString stringWithFormat:@"tel://%@",telNumStrB];
            NSURL *url = [NSURL URLWithString:telephonNumber];
            
            if ([[UIApplication sharedApplication] canOpenURL:url]) {
                
                [[UIApplication sharedApplication] openURL:url];
            }
        }

    }
    
}
-(void)phoneWithCustomWithtel:(NSString *)tel
{
    NSString *allString = tel;
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:allString]];
}

#pragma mark --  风火轮 --
-(void)loadActivityView
{
    indicator = nil;
    indicator = (UIActivityIndicatorView *)[self.view viewWithTag:103];
    
    if (indicator == nil) {
        
        //初始化:
        indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
        
        indicator.tag = 103;
        
        //设置显示样式,见UIActivityIndicatorViewStyle的定义
        indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
        
        
        //设置背景色
        indicator.backgroundColor = [UIColor lightGrayColor];
        
        //设置背景透明
        indicator.alpha = 0.5;
        
        //设置背景为圆角矩形
        indicator.layer.cornerRadius = 6;
        indicator.layer.masksToBounds = YES;
        //设置显示位置
        [indicator setCenter:CGPointMake(KScreenWidth / 2.0, KScreenHeight / 2.0)];
        
        //开始显示Loading动画
        [indicator startAnimating];
        
        [self.view addSubview:indicator];
        
    }
    [indicator startAnimating];
    
}

@end
